package com.scott.classicthreadmodal.demo1.storage;

import com.scott.classicthreadmodal.Product;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * 仓库
 */
public class Storage {

    /**
     * 产品列表
     */
    private BlockingQueue<Product> products = new LinkedBlockingDeque<>(10);

    /**
     * 生产产品
     * @param product 产品
     * @throws InterruptedException 异常
     */
    public void push(Product product) throws InterruptedException {
        products.put(product);
    }

    /**
     * 消费产品
     * @return Product 产品
     * @throws InterruptedException 异常
     */
    public Product pop() throws InterruptedException {
        return products.take();
    }

    public int getTotal(){
        return products.size();
    }
}
